package com.htjc.integral.conversion.util;

import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;


/**
 * 格式化响应信息
 *
 */
public class ResponseUtil {
    public static String formatResponse(JSONObject json, String jsonResult) {
    	String resultStr = "";
    	if (json != null) {
    		if (!json.containsKey("jsonpCallback")) {
    			resultStr = jsonResult;
    		} else {
    			resultStr = json.getString("jsonpCallback") + "(" + jsonResult + ")";
    		}
    	} else {
    		resultStr = jsonResult;
    	}
    	return resultStr; 
    }
    
    public static String formatResponseByRequest(String jsonpCallback, String jsonResult) {
    	String resultStr = "";
		if (StringUtils.isBlank(jsonpCallback)) {
			resultStr = jsonResult;
		} else {
			resultStr = jsonpCallback + "(" + jsonResult + ")";
		}
    	return resultStr; 
    }
}
